package com.galaxy.samson.stock.domain;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import javax.persistence.*;


@NamedQueries({
        /*@NamedQuery(name = "searchByRollNumber",
            query = "select s from Stock s where s.quantity=:quantity"),*/
        @NamedQuery(name = "searchByProductName",
                query = "select s from Stock s where s.productName=:productName"),
        @NamedQuery(name = "searchByCategory",
                query = "select s from Stock s where s.category=:category"),

        @NamedQuery(name = "removeAllStock",
                query = "delete from Stock s")

        /*@NamedQuery(productName = "searchByCity",
                query = "select s from Stock s where s.city=:city")*/
})
@Entity
@Table(name = "Stock")
public class Stock
{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    @Column(nullable = false)
    private String productName;
    @Column(nullable = false)
    private int quantity;
    @Column(nullable = false)
    private messType category;
    @Column(nullable = false)
    private double pricePerQuantity;
    @Column(nullable = false)
    private double totalAmount;

    public enum messType
    {
        VEG, NonVEG, COMMON
    }

    public Stock()
    {
    }


    public Stock(String productName, int quantity, messType category, double pricePerQuantity, double totalAmount)
    {
        this.productName = productName;
        this.quantity = quantity;
        this.category = category;
        this.pricePerQuantity = pricePerQuantity;
        this.totalAmount = totalAmount;

    }

    public int getId()
    {
        return id;
    }

    public String getProductName()
    {
        return productName;
    }

    public void setProductName(String productName)
    {
        this.productName = productName;
    }

    public int getQuantity()
    {
        return quantity;
    }

    public void setQuantity(int quantity)
    {
        this.quantity = quantity;
    }

    public messType getCategory()
    {
        return category;
    }

    public void setCategory(messType category)
    {
        this.category = category;
    }

    public double getPricePerQuantity() {
        return pricePerQuantity;
    }

    public void setPricePerQuantity(double pricePerQuantity) {
        this.pricePerQuantity = pricePerQuantity;
    }

    public double getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(double totalAmount) {
        this.totalAmount = totalAmount;
    }


    @Override
    public int hashCode()
    {
        return HashCodeBuilder.reflectionHashCode(this);
    }

    @Override
    public boolean equals(Object o)
    {
        if(this == o) return true;

        if (o instanceof Stock) {
            Stock otherObject = (Stock) o;


            return EqualsBuilder.reflectionEquals(this, otherObject);
        }
        return false;
    }

    @Override
    public String toString()
    {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }
}



